//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.4/xslt/JavaClass.xsl

package com.novix.struts.action;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.automatedlogic.domino.sso.logout.DominoLogoutConstants;
import com.novix.portal.framework.model.IPortalUser;
import com.novix.portal.framework.model.impl.GeneralUser;
import com.novix.portal.framework.util.IConstants;
import com.novix.portal.framework.util.UserContainer;

/**
 * MyEclipse Struts Creation date: 04-27-2005
 * 
 * XDoclet definition:
 * 
 * @struts:action scope="request"
 */
public class GetUserCaptiveAction extends PortalBaseAction {

    // --------------------------------------------------------- Instance
    // Variables

    // --------------------------------------------------------- Methods

    /**
     * Method execute
     * 
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
        UserContainer uc = new UserContainer();
        request.getSession().setAttribute(IConstants.USER_CONTAINER, uc);
        //capture user's captive & set stylesheet
        String captive = request.getParameter(IConstants.CAPTIVE_QUERY_STRING);
        if (captive != null)
            captive = captive.toLowerCase();
        else
            captive = null;
        
        Cookie cookie = new Cookie(IConstants.CAPTIVE_COOKIE_ID,captive);
		//Cookie cookie = new Cookie(cookieNameLtpaToken, token);
        String ltpaTokenCookieDomain = request.getSession().getServletContext().getInitParameter(IConstants.LPTA_DOMAIN);
		cookie.setDomain(ltpaTokenCookieDomain);
		cookie.setPath("/");
        response.addCookie(cookie);
        //do not default it
        //else
        //	captive = IConstants.DEFAULT_CSS;
        IPortalUser pu = new GeneralUser();
        pu.setCaptive(captive);
        uc.setUser(pu);
        uc.setCaptiveName(captive);

        /**
         * this code should go...
         * 
         * @deprecated
         */
        request.getSession().setAttribute(IConstants.CAPTIVE_ATTRIBUTE, captive);
        /**
         * end
         */
        String iextensionsPath = getApplicationParam(IConstants.IEXTENSIONS_PATH);
        uc.setIextenstionsPath(iextensionsPath);
        String dominoLegacyPath = getApplicationParam(IConstants.DOMINO_LEGACY_PATH);
        uc.setLegacyDominoAppPath(dominoLegacyPath);
        return mapping.findForward(IConstants.SUCCESS);

    }

}